add embedding for all image nfts, show similar nfts in nft page, expo… - #145
Conversation
Code Review — PR #145: NFT Embedding, Similar NFTs, and ExportOverviewThis PR adds three related features:
The overall approach is sound. Below are the issues I found, ordered by severity. Bugs / Correctness Issues
Each similarity hit triggers two sequential canister round-trips ( // Current: 20 × 2 = 40 concurrent canister calls
return Promise.all(
hits.map(async (r) => {
const ownerRes = await adapter.getOwnerOf([tokenId]);
const icpInfo = await adapter.tokenToIcpInfo(tokenId);
...
}),
);
The if (!actor || !arweaveId) throw new Error("actor or arweaveId not ready");
Security Concerns
resp = requests.get(url, timeout=30, stream=True)
data = b""
for chunk in resp.iter_content(chunk_size=1 << 20):
data += chunk
if len(data) > MAX_UPLOAD_BYTES:
raise HTTPException(413, "image exceeds size limit")
This is acceptable for a read-only embedding API, but worth an explicit comment confirming the service holds no secrets or user data, so open CORS is intentional. If the service is later extended with write endpoints, this will need to be revisited.
const EMBEDDING_SERVER =
process.env.REACT_APP_EMBEDDING_SERVER || "https://lbry.youthumber.com";The hardcoded fallback to
Code Quality
embedding = await asyncio.run_in_executor(None, model.encode, img)
When
All other dependencies are pinned to exact versions. Missing Tests / Documentation
Summary
The feature concept is solid and the two-phase lookup (canister fast-path → server fallback) is a nice design. Addressing the N+1 canister calls and the streaming size cap are the two items I'd consider blocking before merge. |
Summary